<template>
    <div class="teacher-item-info">
        <img class="head-img" :src="data.picture || ImgHead" />
            <div class="teacher-content">
                <p class="name">{{data.name}}</p>
                <p class="address">{{data.workPlace}}</p>
                <p class="desc">{{data.description || '暂无简介'}}</p>
            </div>
            <div class="teacher-icon">
                <i class="iconfont icon-bianji" @click="emit('add-lecture', data)"></i>
                <el-popover
                    ref="popoverRef"
                    placement="top"
                    width="280px"
                    trigger="click"
                    popper-class="lecture-popover"
                    :show-arrow="true"
                    :offset="12"
                    :teleported="false">
                    <template #reference>
                        <i class="iconfont icon-shanchu"></i>
                    </template>
                    <div class="del-lecture-confirm">
                        <p class="del-info">删除后不可撤销，确定要删除吗？</p>
                        <div class="btn-list">
                            <el-button class="srt-el-button srt-el-button--cancel srt-el-button-h28 btn" @click="closePopover">取消</el-button>
                            <el-button class="srt-el-button srt-el-button--primary srt-el-button-h28 btn" @click="deleteLecture">确定</el-button>
                        </div>
                    </div>
                </el-popover>
            </div>
    </div>
</template>

<script setup>
import ImgHead from '@/assets/img/mooc/img-head.png';
import { ref } from 'vue';

const emit = defineEmits(['add-lecture', 'delete-lecture'])

const props = defineProps({
    data: {
        type: Object,
        default: () => {}
    }
});

const popoverRef = ref(null);

function deleteLecture () {
    emit('delete-lecture');
    popoverRef.value && popoverRef.value.hide();
}

function closePopover () {
    popoverRef.value && popoverRef.value.hide();
}
</script>

<style lang="scss" scoped>
.teacher-item-info {
    width: 336px;
    height: 160px;
    background: #F7F9FA;
    border-radius: 5px;
    display: flex;
    padding: 14px;
    margin-bottom: 20px;
    margin-right: 16px;
    position: relative;
    border: 1px solid #F7F9FA;
    &:nth-child(3n) {
        margin-right: 0px;
    }
    &:nth-child(3n+1):nth-last-child(-n+3),
    &:nth-child(3n+1):nth-last-child(-n+3)~.li{
        margin-bottom: 0;
    }
    &:hover {
        border: 1px solid #E4E9EE;
    }
    .head-img {
        width: 100px;
        height: 132px;
        border-radius: 4px;
        margin-right: 14px;
    }
    .teacher-content {
        padding-top: 13px;
    }
    .name {
        font-size: 16px;
        color: var(--srt-main-text-color);
        max-width: 108px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1;
    }
    .address {
        font-size: 14px;
        margin-top: 8px;
        max-width: 186px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1;
    }
    .desc {
        width: 100%;
        word-break: break-all;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3; /* 这里是超出几行省略 */
        overflow: hidden;
        margin-top: 14px;
        line-height: 18px;
        color: var(--color-gray);
    }
    .teacher-icon {
        position: absolute;
        right: 16px;
        top: 8px;
        .iconfont {
            font-size: 18px;
            margin-left: 12px;
            cursor: pointer;
            color: var(--srt-color-gray);
            &:hover {
                color: var(--srt-main-active-text-color);
            } 
        }
    }
    .del-lecture-confirm {
        .del-info {
            font-size: 14px;
            font-family: MicrosoftYaHei;
            color: #000000;
            line-height: 24px;
            margin-bottom: 23px;
            &::before {
                content: '\e6a8';
                font-family: 'iconfont';
                font-size: 24px;
                color: var(--srt-color-warning);
                vertical-align: bottom;
                margin-right: 6px;
            }
        }
        .btn-list {
            text-align: right;
            .btn {
                padding: 6px 16px;
            }
        }
    }
}
</style>

<style lang="scss">
.lecture-popover {
    padding: 20px 16px 14px 20px!important;
}
</style>